<?php
declare(strict_types=1);

namespace app\admin\model;

use think\Model;
/**
 * @mixin \think\Model
 */
class Operate extends Model
{
    /**
     * Summary of schema
     * 操作类型
     * 1：登录\退出
     * 2：菜单路由
     * 3：用户板块
     * 4：角色板块
     */
    protected $schema = [
        'id' => 'bigint',
        'content' => 'varchar',
        'create_by' => 'varchar',
        'create_time' => 'datetime',
        'log_type' => 'char',
        'ipaddress' => 'varchar'
    ];
    protected $mapping = [
        'create_by' => 'createBy',
        'create_time' => 'createTime',
        'log_type' => 'logType'
    ];


    public function getLogtypeAttr($value)
    {
        $logtype = [
            '1' => '登录',
            '2' => '退出',
            '3' => '菜单路由',
            '4' => '用户板块',
            '5' => '角色板块',
            '6' => '工具标签',
            '7' => '工具',
            '8' => '笔记'
        ];
        return $logtype[$value];
    }

    public function getMappedField($field)
    {
        $mapping = array_search($field, $this->mapping);
        return $mapping ?? $field;
    }
}
